# 小腿（4-7），0-135(前-后）, 135为平行大腿角度
# 大腿（0-3），走路姿态，0-170（前-后）,打招呼，10-90（前-后）
# 大小腿联动，先收回大腿
class Leg:
    CALF_MIN = 0
    CALF_MID = 90
    CALF_MAX = 135
    THIGH_MIN = 10
    THIGH_MID = 90
    THIGH_MAX = 170

    # 猫的卧姿
    GET_DOWN_CALF = CALF_MIN
    GET_DOWN_THIGH = THIGH_MAX

    # 站姿的舵机角度
    STAND_CALF = 50
    STAND_THIGH = 170

    # 打招呼的舵机角度
    SAY_HELLO_CALF_1 = 45
    SAY_HELLO_CALF_2 = 90
    SAY_HELLO_THIGH = 60

    # 前进的舵机角度
    FORWARD_BEHIND_CALF_1 = 50
    FORWARD_BEHIND_THIGH_1 = 170
    FORWARD_FRONT_CALF_1 = 45
    FORWARD_FRONT_THIGH_1 = 140

    FORWARD_BEHIND_CALF_2 = 50
    FORWARD_BEHIND_THIGH_2 = 170
    FORWARD_FRONT_CALF_2 = 50
    FORWARD_FRONT_THIGH_2 = 135

    FORWARD_BEHIND_CALF_3 = 53
    FORWARD_BEHIND_THIGH_3 = 170
    FORWARD_FRONT_CALF_3 = 50
    FORWARD_FRONT_THIGH_3 = 150

    FORWARD_BEHIND_CALF_4 = 50
    FORWARD_BEHIND_THIGH_4 = 170
    FORWARD_FRONT_CALF_4 = 45
    FORWARD_FRONT_THIGH_4 = 140

    # 后退的舵机角度
    RETREAT_BEHIND_CALF_1 = 50
    RETREAT_BEHIND_THIGH_1 = 170
    RETREAT_FRONT_CALF_1 = 40
    RETREAT_FRONT_THIGH_1 = 140

    RETREAT_BEHIND_CALF_2 = 50
    RETREAT_BEHIND_THIGH_2 = 170
    RETREAT_FRONT_CALF_2 = 53
    RETREAT_FRONT_THIGH_2 = 130

    RETREAT_BEHIND_CALF_3 = 50
    RETREAT_BEHIND_THIGH_3 = 170
    RETREAT_FRONT_CALF_3 = 53
    RETREAT_FRONT_THIGH_3 = 130

    RETREAT_BEHIND_CALF_4 = 50
    RETREAT_BEHIND_THIGH_4 = 170
    RETREAT_FRONT_CALF_4 = 45
    RETREAT_FRONT_THIGH_4 = 140

    def __init__(self, calf_in, thigh_in):
        self.calf = calf_in
        self.thigh = thigh_in

    def deal_out_range_angle(self):
        if self.calf < Leg.CALF_MIN:
            self.calf = Leg.CALF_MIN
        elif self.calf > Leg.CALF_MAX:
            self.calf = Leg.CALF_MAX

        if self.thigh < Leg.THIGH_MIN:
            self.thigh = Leg.THIGH_MIN
        elif self.thigh > Leg.THIGH_MAX:
            self.thigh = Leg.THIGH_MAX


class Action:
    STEER_TYPE = 0
    POSE_TYPE = 1
    WAIT_TYPE = 2

    # 猫的姿势定义
    GET_DOWN = 0
    STAND = 1
    SITDOWN = 2

    def __init__(self):
        self.type = Action.STEER_TYPE
        self.legs = []
        self.pose = Action.SITDOWN
        self.wait_time = 0
